//
//  MeetingIndrotucationController.swift
//  YiYaoHui
//
//  Created by HM on 16/1/16.
//  Copyright © 2016年 TMPercy. All rights reserved.
//

import UIKit

class MeetingIndrotucationController: UIViewController {
    
    @IBOutlet weak var introducationTableView: UITableView!
    
    @IBOutlet weak var watchMeetingButton: UIButton!
    
    
    var meeting : Meeting!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        introducationTableView.delegate = self
        introducationTableView.dataSource = self
        setUpUI()
    }
    
    func setUpUI() {
        self.automaticallyAdjustsScrollViewInsets = false
        
       introducationTableView.estimatedRowHeight = 100
       introducationTableView.rowHeight = UITableViewAutomaticDimension
        
        introducationTableView.separatorColor = UIColor.whiteColor()
        watchMeetingButton.layer.cornerRadius = 5.0
    }
    
    override func viewWillAppear(animated: Bool) {
        UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffset(horizontal: 0, vertical: -60), forBarMetrics: .Default)
        navigationController?.navigationBarHidden = false
        tabBarController?.tabBar.hidden = true
    }
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    
    @IBAction func watchMeeting(sender: AnyObject) {
        
        let meetingController = self.storyboard?.instantiateViewControllerWithIdentifier("concreteMeetingController") as! MeetingDetailController

        meetingController.meetingURL = meeting.pageURL
        meetingController.meetingTitle = meeting.name
        meetingController.id = 1
        self.navigationController?.pushViewController(meetingController, animated: true)
    }
}

extension MeetingIndrotucationController: UITableViewDataSource {
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        switch indexPath.row {
        case 0:
            let cell = tableView.dequeueReusableCellWithIdentifier("cell1")! as! MeetingNameCell
            cell.label.text = meeting.name
            return cell
        case 1:
            let cell = tableView.dequeueReusableCellWithIdentifier("cell2")! as! EnterpriseNameCell
            cell.enterpriselabel.text = meeting.enterpriseName
            cell.dateLabel.text = meeting.commitDate
            return cell
        default:
            let cell = tableView.dequeueReusableCellWithIdentifier("cell3") as! MeetingIntroducationCell
            cell.label.text = meeting.content
            cell.label.font = UIFont.systemFontOfSize(15)
            
            return cell
        }
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 3
    }
}

extension MeetingIndrotucationController: UITableViewDelegate {
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        tableView.deselectRowAtIndexPath(indexPath, animated: true)
    }
}












